package com.ruoyi.system.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@Component
@Aspect
public class LognsAop {

    @Autowired
    HttpServletRequest request;
    @Before("execution(* com.ruoyi.system.controller.*.*(..))")
    public void before(JoinPoint joinPoint){
        //pom文件最后两个是aop所需要的依赖
        System.err.println("====================方法名=================="+joinPoint.getSignature().getName());
        //打印ip地址
        String remoteAddr = request.getRemoteAddr();
        System.err.println("======================打印的ip==================="+remoteAddr);
        //打印时间
        LocalDate localDate = LocalDate.now();
        //转换时间类型
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String format = localDate.format(formatter);
        //打印出写操作时间
        System.err.println("==================打印时间==================="+format);
        //打印用的信息
        System.err.println("is accessing the method: "+joinPoint.getSignature().toLongString());
    }
}
